package rds

import (
	"fmt"
	"gin-base/base/config"
	"github.com/garyburd/redigo/redis"
)

type Connect struct {
	Rs redis.Conn
}

var host string

func init() {
	if config.Ini.String("app.mode") == "prod" {
		host = config.Ini.String("redis.host")
	} else {
		host = config.Ini.String("redis.host_dev")
	}
}
func Open() *Connect {
	db := config.Ini.String("redis.db_num")

	// tcp连接redis
	rs, err := redis.Dial("tcp", host)

	// 若连接出错，则打印错误信息，返回
	if err != nil {
		fmt.Println(err)
		fmt.Println("redis connect error")
	}

	//选择db
	rs.Do("SELECT", db)

	con := new(Connect)
	con.Rs = rs
	return con
}
